package com.cw.jeeyt.service.converter.facade;

import java.util.Date;
import java.util.List;

import com.cw.jeeyt.service.bo.facade.FacadeParamFieldBo;
import com.cw.jeeyt.core.util.SessionUtil;
import com.cw.jeeyt.dao.model.facade.FacadeParamFieldDo;
import com.cw.jeeyt.api.dto.facadeExcel.ApiParamField;
import com.cw.lang.common.utils.CollectionUtil;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;

/**
 * 接口参数字段转换类
 *
 * @author chenw
 * @date 2019-11-02 14:16:40
 */
public class FacadeParamFieldConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static FacadeParamFieldBo do2Bo(FacadeParamFieldDo model) {
        if (model == null) {
            return null;
        }
        return FacadeParamFieldBo.builder()
            .id(model.getId())
            .fieldCode(model.getFieldCode())
            .fieldType(model.getFieldType())
            .required(model.getRequired())
            .maxLength(model.getMaxLength())
            .minLength(model.getMinLength())
            .fieldDesc(model.getFieldDesc())
            .fieldDemo(model.getFieldDemo())
            .createBy(model.getCreateBy())
            .createDate(model.getCreateDate())
            .updateBy(model.getUpdateBy())
            .updateDate(model.getUpdateDate())
            .build();
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static FacadeParamFieldDo bo2Do(FacadeParamFieldBo bo) {
        if (bo == null) {
            return null;
        }
        FacadeParamFieldDo model = new FacadeParamFieldDo();
        model.setId(bo.getId());
        model.setFieldCode(bo.getFieldCode());
        model.setFieldType(bo.getFieldType());
        model.setRequired(bo.getRequired());
        model.setMaxLength(bo.getMaxLength());
        model.setMinLength(bo.getMinLength());
        model.setFieldDesc(bo.getFieldDesc());
        model.setFieldDemo(bo.getFieldDemo());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<FacadeParamFieldBo> doList2BoList(List<FacadeParamFieldDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return null;
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(),FacadeParamFieldConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<FacadeParamFieldDo> boList2DoList(List<FacadeParamFieldBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return null;
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(),FacadeParamFieldConverter::bo2Do));
    }

    /**
     * apiParamField转do
     *
     * @param paramField
     * @return
     */
    public static FacadeParamFieldDo apiParamField2Do(ApiParamField paramField) {
        if (paramField == null) {
            return null;
        }
        FacadeParamFieldDo model = new FacadeParamFieldDo();
        model.setFieldCode(paramField.getFieldCode());
        model.setFieldType(paramField.getFieldType());
        model.setRequired(paramField.getIsRequired());
        //model.setMaxLength(paramField.ge);
        //model.setMinLength(paramField.);
        model.setFieldDesc(paramField.getFieldName());
        //model.setFieldDemo(dto.getFieldDemo());
        model.setCreateBy(SessionUtil.getSessionUserId());
        model.setCreateDate(new Date());
        model.setUpdateBy(SessionUtil.getSessionUserId());
        model.setUpdateDate(new Date());
        return model;
    }
    /**
     * dtoList转doList
     *
     * @param dtoList
     * @return
     */
    public static List<FacadeParamFieldDo> apiParamFieldList2DoList(List<ApiParamField> dtoList) {
        if (CollectionUtil.isEmpty(dtoList)) {
            return null;
        }
        return Lists.newArrayList(Iterators.transform(dtoList.iterator(),FacadeParamFieldConverter::apiParamField2Do));
    }
}
